package com.heiyu.api.conf;

import com.heiyu.api.response.BaseResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

@ControllerAdvice
public class GlobalExceptionController {

    private final static Logger log = LoggerFactory.getLogger(GlobalExceptionController.class);

    @ExceptionHandler
    @ResponseBody
    public BaseResponse unknowException(Exception e, HttpServletResponse response){
        BaseResponse resp = new BaseResponse();
        log.error("系统异常："+e.getMessage());
        e.printStackTrace();
        resp.systemError();
        return resp;
    }
}
